﻿using System;
using System.Collections.Generic;
using System.Text;

namespace YesBlog.Framework
{
    public class Result
    {
        /// <summary>
        /// 状态
        /// </summary>
        public bool IsSuccess { get; set; }

        /// <summary>
        /// 提示
        /// </summary>
        public string Message { get; set; }


        protected Result()
        {
        }

        public static Result Fail(string message)
        {
            return new Result
            {
                IsSuccess = false,
                Message = message
            };
        }

        public static Result Success()
        {
            return Success(string.Empty);
        }

        public static Result Success(string message)
        {
            return new Result
            {
                IsSuccess = true,
                Message = message
            };
        }


    }

    public class Result<T> : Result
    {
        /// <summary>数据
        /// </summary>
        public T Data { get; set; }

        private Result() { }

        public new static Result<T> Fail(string message)
        {
            return new Result<T>
            {
                IsSuccess = false,
                Message = message
            };
        }

        public static Result<T> Fail(T data, string message)
        {
            return new Result<T>
            {
                IsSuccess = false,
                Message = message,
                Data = data
            };
        }


        public static Result<T> Success(T data)
        {
            return Success(data, string.Empty);
        }

        public static Result<T> Success(T data, string message)
        {
            return new Result<T>
            {
                IsSuccess = true,
                Message = message,
                Data = data
            };
        }

    }
}
